package com.clock.web.controller.shop;

import com.clock.common.annotation.Log;
import com.clock.common.core.controller.BaseController;
import com.clock.common.core.domain.AjaxResult;
import com.clock.common.core.page.TableDataInfo;
import com.clock.common.enums.BusinessType;
import com.clock.common.utils.poi.ExcelUtil;
import com.clock.shop.domain.ShopMember;
import com.clock.shop.service.IShopMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 会员Controller
 * 
 * @author ruoyi
 * @date 2024-10-11
 */
@RestController
@RequestMapping("/shop/member")
public class ShopMemberController extends BaseController
{
    @Autowired
    private IShopMemberService shopMemberService;

    /**
     * 查询会员列表
     */
    @PreAuthorize("@ss.hasPermi('shop:member:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShopMember shopMember)
    {
        startPage();
        List<ShopMember> list = shopMemberService.selectShopMemberList(shopMember);
        return getDataTable(list);
    }

    /**
     * 导出会员列表
     */
    @PreAuthorize("@ss.hasPermi('shop:member:export')")
    @Log(title = "会员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShopMember shopMember)
    {
        List<ShopMember> list = shopMemberService.selectShopMemberList(shopMember);
        ExcelUtil<ShopMember> util = new ExcelUtil<ShopMember>(ShopMember.class);
        util.exportExcel(response, list, "会员数据");
    }

    /**
     * 获取会员详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:member:query')")
    @GetMapping(value = "/{memberId}")
    public AjaxResult getInfo(@PathVariable("memberId") Long memberId)
    {
        return success(shopMemberService.selectShopMemberByMemberId(memberId));
    }

    /**
     * 新增会员
     */
    @PreAuthorize("@ss.hasPermi('shop:member:add')")
    @Log(title = "会员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShopMember shopMember)
    {
        return toAjax(shopMemberService.insertShopMember(shopMember));
    }

    /**
     * 修改会员
     */
    @PreAuthorize("@ss.hasPermi('shop:member:edit')")
    @Log(title = "会员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShopMember shopMember)
    {
        return toAjax(shopMemberService.updateShopMember(shopMember));
    }

    /**
     * 删除会员
     */
    @PreAuthorize("@ss.hasPermi('shop:member:remove')")
    @Log(title = "会员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{memberIds}")
    public AjaxResult remove(@PathVariable Long[] memberIds)
    {
        return toAjax(shopMemberService.deleteShopMemberByMemberIds(memberIds));
    }
}
